package game.game;


import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;



public class TestGame extends Frame {
    Image ball = Toolkit.getDefaultToolkit().getImage("D:\\ideaProjects\\01-javaSE\\day02-IDEA\\src\\game\\imges\\ball.png");
    Image desk = Toolkit.getDefaultToolkit().getImage("D:\\ideaProjects\\01-javaSE\\day02-IDEA\\src\\game\\imges\\desk.png");

    double x = 100;
    double y = 100;

    double degree = 3.14 / 3;

    public void paint(Graphics g){
        System.out.println("窗口被化了一次");
        g.drawImage(desk,0,0,null);
        g.drawImage(ball,(int)x ,(int) y,null);
        x = x + 10 * Math.cos(degree);
        y = y + 10 * Math.cos(degree);
        if (y > 480 - 30 - 40) {
            degree = -degree;
        }
        if (x > 856 - 30 - 40) {
            degree = 3.14 - degree;
        }
        if (x < 20 + 20) {
            degree = 3.14 - degree;
        }
        if (y < 20 + 20) {
            degree = -degree;
        }

    }

    void lauchFrame(){
        setSize(856,488);
        setLocation(50,50);
        setTitle("软帝--程序猿作品");
        setVisible(true);
        while (true){
            repaint();
            try {
                Thread.sleep(40);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        System.out.println("软帝--程序猿作品");
        TestGame tg = new TestGame();
        tg.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        tg.lauchFrame();
    }

}
